﻿using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;
using Pay.DTO.card;

namespace Pay.Service.AutoMapper {

    public class CollectMapper : IStartupDto {
        private IMapperConfigurationExpression _cfg;
        public CollectMapper(IMapperConfigurationExpression cfg) {
            _cfg = cfg;
        }
        public void Execute() {
            Create();
        }
        protected virtual void Create() {
            _cfg.CreateMap<Collect, collect_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
                .ForMember(dest => dest.product_id, src => src.MapFrom(c => c.ProductId))
                .ForMember(dest => dest.craete_time, src => src.MapFrom(c => c.CraeteTime.ToDateTime()))
                .ForMember(dest => dest.product, src => src.MapFrom(c => c.Product))  ;

            _cfg.CreateMap<collect_dto,Collect>()
              .ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
              .ForMember(dest => dest.MerchantId, src => src.MapFrom(c => c.merchant_id))
              .ForMember(dest => dest.ProductId, src => src.MapFrom(c => c.product_id))
              .ForMember(dest => dest.CraeteTime, src => src.MapFrom(c => c.craete_time.ToUnix()))
              .ForMember(dest => dest.Product, src => src.MapFrom(c => c.product));
        }
    }
}
